package com.example.monitoring.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 监控配置属性类
 * 
 * @author rsz
 * @since 2024-04-13
 */
@Data
@Component
@ConfigurationProperties(prefix = "monitoring")
public class MonitoringProperties {

    private Config config;
    private List<TargetService> targetService = new ArrayList<>();
    private NetworkCheck networkCheck;
    private Middleware middleware;
    private Report report;

    @Data
    public static class Config {
        private String filePath;
    }

    @Data
    public static class TargetService {
        private String name;
        private String url;
        private String method;
        private Integer expectedRespCode;
        private Integer respCode;
        private Long checkInterval;
    }

    @Data
    public static class NetworkCheck {
        private List<Service> services;
        private List<ServiceGroup> groups;

        @Data
        public static class ServiceGroup {
            private String name;
            private String description;
            private String category;
            private List<Service> services;
        }

        @Data
        public static class Service {
            private String name;
            private String host;
            private Integer port;
            private String type;
            /**
             * 连接类型: 直连(direct)或间连(indirect)
             */
            private String connectionType = "direct";
            /**
             * 标签: 如"生产环境", "内网服务器", "数据库服务器"等
             */
            private String label;
            /**
             * 是否为域名服务
             */
            private boolean isDomain = false;
            /**
             * 域名解析超时时间(毫秒)
             */
            private int dnsTimeout = 5000;
            /**
             * 服务描述
             */
            private String description;
        }
    }

    @Data
    public static class Middleware {
        private Jvm jvm;
        private Redis redis;
        private Elasticsearch elasticsearch;
        private MySQL mysql;
        private MinIO minio;

        @Data
        public static class Jvm {
            private boolean enabled;
            private String url;
            private String username;
            private String password;
        }

        @Data
        public static class Redis {
            private boolean enabled;
            private String host;
            private int port;
            private String password;
        }

        @Data
        public static class Elasticsearch {
            private boolean enabled;
            private String hosts;
            private String username;
            private String password;
        }

        @Data
        public static class MySQL {
            private boolean enabled;
            private String url;
            private String username;
            private String password;
        }

        @Data
        public static class MinIO {
            private boolean enabled;
            private String endpoint;
            private String accessKey;
            private String secretKey;
        }
    }

    @Data
    public static class Report {
        private String exportPath;
        private String templatePath;
    }
} 